/*
 * @Description:
 * @Version: 1.0
 * @Autor: gaoluo
 * @Date: 2021-11-23 11:09:50
 * @LastEditors: gaoluo
 * @LastEditTime: 2021-11-23 14:20:01
 * @FilePath: /nhw/src/utils/touchBack.js
 */

/**
 *  用来检测左右滑动距离，然后执行回调
 * @param {*} id 元素Id
 * @param {*} callback 回调函数
 * @param {*} num 滑动距离 默认100px
 */
export default function init(id, callback, num = 100) {
  const app = document.getElementById(id);
  let start = 0;
  //绑定事件
  app.addEventListener('touchmove', (e) => {
    if (e.touches[0].clientX - start > num) {
      callback();
    }
  })
  app.addEventListener('touchstart', (e) => {
    start = e.touches[0].clientX;
  })
  app.addEventListener('touchend', (e) => {
    start = 0;
  })
}
